﻿using System;
using System.Globalization;
using Freshbooks.Model;
using Freshbooks.Properties;
using RestSharp;

namespace Freshbooks
{
    public class CallbackService
    {
        private readonly FreshbooksApi _client;

        protected internal CallbackService(FreshbooksApi client)
        {
            _client = client;
        }

        public int CreateCallback(Callback callback)
        {
            var request = _client.GetRequest();

            request.AddParameter("text/xml", Resources.callback_create
                .Replace("$EVENT$", callback.Event)
                .Replace("$URI$", callback.Uri), ParameterType.RequestBody);

            return _client.Execute<int>(request);
        }

        public bool DeleteCallback(int callbackId)
        {
            var request = _client.GetRequest();

            request.AddParameter("text/xml",
                                 Resources.callback_delete
                                     .Replace("$ID$", callbackId.ToString(CultureInfo.InvariantCulture)),
                                 ParameterType.RequestBody);

            return _client.Execute<bool>(request);
        }

        public Callbacks ListCallbacks(CommandCallback commandCallback)
        {
            var request = _client.GetRequest();

            request.AddParameter("text/xml", Resources.callback_list, ParameterType.RequestBody);

            return _client.Execute<Callbacks>(request);
        }

        public bool ResendToken(int callbackId)
        {
            throw new NotImplementedException();
        }

        public bool VerifyCallback(int callbackId, string verifier)
        {
            throw new NotImplementedException();
        }
    }
}
